// $codepro.audit.disable
package edu.gatech.team404.junit;

import java.util.ArrayList;

import edu.gatech.team404.Course;
import edu.gatech.team404.dal.CourseDAL;
import junit.framework.TestCase;

public class CourseDALTest extends TestCase
{
	Course course = new Course ("CS 1337", "This is a test course.", "instructor");
	
	protected void setUp() throws Exception {
		super.setUp();
	}
	
	public void testCreateCourse() {
		CourseDAL dal = new CourseDAL();
		dal.createCourse(course);
		assertEquals(course.getName(), dal.getCourseByName(course.getName()).getName());
	}
	
	public void testGetCoursesByInstructor() {
		CourseDAL dal = new CourseDAL();
		assertEquals(course.getName(), dal.getCoursesByInstructor(course.getInstructor()).get(0).getName());
	}
	
	public void testGetAllCourses() {
		CourseDAL dal = new CourseDAL();
		assertEquals(course.getName(), dal.getAllCourses().get(0).getName());
	}
	
	public void testUpdateCourse() {
		CourseDAL dal = new CourseDAL();
		course.setDescription("This is an updated version of the test course.");
		dal.updateCourse(course);
		assertEquals(course.getDescription(), dal.getCourseByName(course.getName()).getDescription());
	}
	
	public void testDeleteCourse() {
		CourseDAL dal = new CourseDAL();
		dal.deleteCourse(course.getName());
		assertNull(dal.getCourseByName(course.getName()));
	}
	
	public void testSignUpForCourse() {
		CourseDAL dal = new CourseDAL();
		
		//Assuming that there is an account with "student" as the username
		dal.signUpForCourse("student", course);
		assertEquals("student", dal.getStudents(course.getName()).get(0).getUsername());
	}
	
	public void testGetCoursesByStudent() {
		CourseDAL dal = new CourseDAL();
		ArrayList<Course> courses = (ArrayList<Course>) dal.getCoursesByStudent("student");
		assertEquals("CS 1337", courses.get(0).getName());
	}
}
